import Store from '@/store';
import { redirect, useNavigate } from 'react-router-dom';

export default function Login() {
  const navigate = useNavigate();
  const login = () => {
    Store.dispatch(Store.actions.user.setRole('admin'));
    navigate('/');
  };
  return (
    <main className=" w-full h-full flex items-center justify-center">
      <button className="bg-gray-500 p-2 border  px-5 text-white font-bold shadow-md " onClick={login}>
        登录
      </button>
    </main>
  );
}

export function loginLoader() {
  const role = Store.store.getState().user.role;
  console.log(`role ==>`,role);
  /**判断是否登录，登录就跳转首页 */
  if (role) {
    return redirect('/');
  }
  return null;
}
